
import {Button,} from 'antd';
import {WeaTab,WeaSearchGroup,WeaFormItem} from 'ecCom';
import {inject,observer} from "mobx-react";
import {toJS} from 'mobx';
import {WeaTableNew,WeaSwitch} from 'comsMobx';
const WeaTable = WeaTableNew.WeaTable;
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

@observer
export default class CptModify extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
        const {contentStore} = this.props;
        const {showSearchAd,modifyTableStore,modifyForm,cptModifyCondition} = contentStore;
        const formParams = modifyForm.getFormParams() || {};
            return (
                <div >
                    <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@jqjqg4`}
                        buttonsAd={this.getAdButtons()}
                        searchType={['advanced']}
                        setShowSearchAd={bool=>{contentStore.setShowSearchAd(bool)}}
                        hideSearchAd={()=> contentStore.setShowSearchAd(false)}
                        searchsAd={
                            <div>{this.getCondition()}</div>
                        }
                        showSearchAd={showSearchAd}
                    />
                    <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@jm5ia5`} 
                        comsWeaTableStore={modifyTableStore}
                        hasOrder={true}
                        needScroll={true}
                    />
                </div>)
        }
       
    
    getAdButtons = () => {
        const {contentStore} = this.props;
        const {getModifyList,setShowSearchAd,clearFormFields1} = contentStore;
        return [
            (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@5m3ie2@search`} type="primary" onClick={()=>{getModifyList();setShowSearchAd(false);}}>{getLabel(197,'搜索') }</Button>),
            (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@0q4agi@reset`} type="ghost" onClick={()=>{clearFormFields1();}}>{getLabel(2022,'重置') }</Button>),
            (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@bia942@close`} type="ghost" onClick={()=>{setShowSearchAd(false)}}>{getLabel(201,'取消') }</Button>)
        ];
    }
    getCondition=()=>{
        const { cptModifyCondition, modifyForm } = this.props.contentStore;
        const {isFormInit} = modifyForm;
        let group = [];
        const formParams = modifyForm.getFormParams();
        isFormInit &&  cptModifyCondition.map((c,i) =>{
          let items = [];
          c.items.map((fields,index) => {
            items.push({
              com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@2px9b1@${index}`}
                  label={`${fields.label}`}
                  labelCol={{span: `${fields.labelcol}`}}
                  wrapperCol={{span: `${fields.fieldcol}`}}>
                        <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@qtzx0x@${index}`} fieldConfig={fields} form={modifyForm} onEnterSearch={this.onEnterSearch} />
                  </WeaFormItem>),
              colSpan:1,
            })
          });
          group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@pc3unc@${i}`} needTigger={true} title={c.title} showGroup={c.defaultshow} items={items}/>)
        });
        return group;
    }

    onEnterSearch = () =>{
        const { getModifyList, setShowSearchAd } = this.props.contentStore;
        getModifyList();
        setShowSearchAd(false);
    }

}

